In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import plotly.express as px
In [2]:
import os
In [3]:
DATA_FOLDER = os.getcwd()
In [4]:
print(DATA_FOLDER)
/Users/radhika/Downloads
In [5]:
%cd /Users/radhika/Downloads/Radhika-maps/Stories
/Users/radhika/Downloads/Radhika-maps/Stories
In [6]:
DATA_FOLDER = os.getcwd()
In [7]:
print(DATA_FOLDER)
/Users/radhika/Downloads/Radhika-maps/Stories
In [8]:
PREPROCESS_FOLDER  = f"{DATA_FOLDER}/population_plot"
OUTPUT_FOLDER = f"{DATA_FOLDER}/output"
DF_CSV = f"{PREPROCESS_FOLDER}/Data_2095.csv"
Splot_HTML_OUTPUT = f'{OUTPUT_FOLDER}/tfrvsbirth_index.html'
In [9]:
df = pd.read_csv(DF_CSV)
In [10]:
df.head()
Out[10]:
S.no. Year State TFR Pop PR Birth BR
0 1 2010 andaman & nicobar islands 1.59 380572 0.096029 28926 0.026965
1 2 2010 andhra pradesh 1.77 84573062 0.046867 7020689 -0.035690
2 3 2010 arunachal pradesh 1.86 1383715 0.094695 116947 0.077787
3 4 2010 assam 2.53 31205555 0.073214 3539909 -0.028166
4 5 2010 bihar 3.41 104097888 0.082118 13015567 -0.015003
In [11]:
type(df['Pop'])
Out[11]:
pandas.core.series.Series
In [12]:
df = df.rename(columns={'BR':'Birth Rate','TFR':'Total Fertility Rate'})
In [13]:
df['Pop']= df['Pop'].astype(int)
df['Birth']=df['Birth'].astype(int)
In [14]:
df['Pop in Million']=df['Pop']/1000000
df['Birth per Thousand']=df['Birth']/1000
In [15]:
df.head()
Out[15]:
S.no. Year State Total Fertility Rate Pop PR Birth Birth Rate Pop in Million Birth per Thousand
0 1 2010 andaman & nicobar islands 1.59 380572 0.096029 28926 0.026965 0.380572 28.926
1 2 2010 andhra pradesh 1.77 84573062 0.046867 7020689 -0.035690 84.573062 7020.689
2 3 2010 arunachal pradesh 1.86 1383715 0.094695 116947 0.077787 1.383715 116.947
3 4 2010 assam 2.53 31205555 0.073214 3539909 -0.028166 31.205555 3539.909
4 5 2010 bihar 3.41 104097888 0.082118 13015567 -0.015003 104.097888 13015.567
In [16]:
fig= px.scatter(df,x= "Total Fertility Rate", y= "Birth per Thousand", animation_frame="Year", animation_group="State",size="Pop in Million",color="State",
         hover_data={'Birth per Thousand' :True,'State' :True, 'Pop in Million' :True,'Total Fertility Rate' :True},
                log_x=False, size_max=90, title='Birth vs TFR'
        )
    
fig.update_layout(yaxis_title="Birth per Thousand", plot_bgcolor='black',paper_bgcolor='black')
fig.update_xaxes(showgrid=False)
fig.update_yaxes(showgrid=False)
fig.update_layout(width=1000, height=800)
fig.update_layout(
    font=dict(
        color='white' 
    )
)

 
fig.write_html(Splot_HTML_OUTPUT)

fig
In [ ]: